#include "tr_addstationdialog.h"
#include "ui_tr_addstationdialog.h"

#include "DataStruct.h"
#include "StationManagement.h"
#include "trainmanagement.h"

Tr_AddStationDialog::Tr_AddStationDialog(int index, QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Tr_AddStationDialog)
{
    ui->setupUi(this);
    currentRow = index;
}

Tr_AddStationDialog::~Tr_AddStationDialog()
{
    delete ui;
}

void Tr_AddStationDialog::on_pushButton_clicked()
{
    QString queryConditon = ui->lineEdit->text();

    //Determine whether null or empty
    if(queryConditon.isNull()||queryConditon.isEmpty())
        return;

    Station station = StationManagement::queryStation(queryConditon);

    ui->id_label->setText(QString::number(station.ID));
    ui->name_label->setText(station.name);

    return;
}

void Tr_AddStationDialog::on_buttonBox_accepted()
{
    Station s;
    s.ID = ui->id_label->text().toInt();
    s.name = ui->name_label->text();

    TrainManagement::addStation(s, ui->timeEdit->time(), currentRow);
}
